package com.jiazhong.basic.pack0524.manytoone.dao;

import com.jiazhong.basic.pack0524.db.DBManager;
import com.jiazhong.basic.pack0524.manytoone.bean.Dept;
import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DeptDAO {
    private Connection conn;
    private PreparedStatement ps;
    private ResultSet rs;
    @SneakyThrows
    public Dept findById(int deptNo){
        conn = DBManager.getConnection();
        String sql = "select * from dept where deptno=?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1,deptNo);
        rs = ps.executeQuery();
        if(rs.next()){
            Dept dept = new Dept();
            dept.setDeptNo(rs.getInt(1));
            dept.setDname(rs.getString(2));
            dept.setLoc(rs.getString(3));
            return dept;
        }
        return null;
    }
}
